﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LearningBubbles
{
    static class Queries
    {
        static public cvesjrueEntities3 context = new cvesjrueEntities3();

        public static List<assignment> GetAssignments()
        {
            var assignments = from a in context.assignment
                              select a;
            return assignments.ToList<assignment>();
        }

        public static assignment GetAssignment(int id)
        {
            var ass = from a in context.assignment
                              where a.id == id
                              select a;
            return ass.FirstOrDefault();
        }

        public static List<element> GetElements(int assId)
        {
            var elements = from e in context.element
                           where e.assId == assId
                           select e;
            List<element> list1 = new List<element>();

            return new List<element>(SortElements(elements.ToList<element>()));
        }

        public static List<element> SortElements(List<element> elements)
        {
            List<int> newList = new List<int>();
            foreach (element e in elements)
                newList.Add(e.id);
            newList.Sort();
            List<element> newList1 = new List<element>();
            foreach (int i in newList)
            {
                foreach (element e in elements)
                {
                    if (e.id == i)
                    {
                        newList1.Add(e);
                    }
                }
            }
            return newList1;
            
            
        }

        public static List<bogus> GetBogus(int elementId)
        {
            var boguses = from b in context.bogus
                          where b.elementId == elementId
                          select b;
            return boguses.ToList<bogus>();
        }
    }
}
